// Initializes the `quote` service on path `/quote`
const createService = require('feathers-sequelize');
const createModel = require('../../models/quote.model');
const hooks = require('./quote.hooks');

module.exports = function (app) {
  const Model = createModel(app);
  const paginate = app.get('paginate');

  const options = {
    Model,
    paginate,
  };


  // Initialize our service with any options it requires
  app.use('/quote', createService(options));
  app.use('/quoteTest', {
    find: async ({query}) => {
      let result = []
      for(var key in app.globalData.quote) {
        if(key.split('_')[3] === query.coin) {
          result.push(app.globalData.quote[key])
        }
      }
      return result
    }
  });
  // Get our initialized service so that we can register hooks
  const service = app.service('quote');

  service.hooks(hooks);
};
